package cn.smp.server.handler;

import cn.smp.message.GroupQuitRequestMessage;
import cn.smp.server.session.Group;
import cn.smp.server.session.GroupSessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

@ChannelHandler.Sharable
public class GroupQuitRequestMessageHandler extends SimpleChannelInboundHandler<GroupQuitRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupQuitRequestMessage msg) throws Exception {
        final String groupName = msg.getGroupName();
        final String username = msg.getUsername();
        final Group group = GroupSessionFactory.getGroupSession().removeMember(groupName,msg.getUsername());
        if (group == null) {
            ctx.writeAndFlush(new GroupQuitRequestMessage(username,groupName));
        }

        //发送退群成功消息

        //通知群成员
    }
}
